//
//  SISSPassengerTakeLookRecordViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/4.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerTakeLookRecordViewController.h"
#import "SISSPassengerTakeLookDetailViewController.h"
#import "SISSAddPassengerTakeLookViewController.h"
#import "SISSImportantPassengerTakeLookRecordCell.h"
#import "SISSPassengerProgressModel.h"
#import "SISSPassengerProgressRecordInfoModel.h"
#import "SISSNetworkingManager+PassengerProgress.h"

static NSString *impotantPassengerTakeLookRecordCellReuseID = @"impotantPassengerTakeLookRecordCellReuseID";
@interface SISSPassengerTakeLookRecordViewController ()

/* 带看模型数组 */
@property (strong, nonatomic) NSArray<SISSPassengerTakeLookModel *> *takeLookArr;

@end

@implementation SISSPassengerTakeLookRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[SISSImportantPassengerTakeLookRecordCell class] forCellReuseIdentifier:impotantPassengerTakeLookRecordCellReuseID];

    WeakSelf
    [kSISSRefresh prepareHeaderRefresh:self.tableView loadDataBlock:^{
        kSISSRefresh.refreshType = SISSRefressTypeUpDown;
        [weakSelf upDownLoadData];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self requestPassengerTakeLookRecordData];
}

- (void)addRecordButtonDidClickAction {
    [super addRecordButtonDidClickAction];
    if (self.passengerProgressRecordInfoModel.businessStatus == 2) {
        [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
        return;
    }
    SISSAddPassengerTakeLookViewController *vc = [[SISSAddPassengerTakeLookViewController alloc] init];
    vc.passengerProgressModel = self.passengerProgressModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.takeLookArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SISSImportantPassengerTakeLookRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:impotantPassengerTakeLookRecordCellReuseID forIndexPath:indexPath];
    cell.isHiddenCheckButton = YES;
    cell.takeLookModel = self.takeLookArr[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    SISSPassengerTakeLookDetailViewController *vc = [[SISSPassengerTakeLookDetailViewController alloc] init];
    vc.passengerProgressModel = self.passengerProgressModel;
    vc.takeLookModel = self.takeLookArr[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)upDownLoadData {
    
    [self requestPassengerTakeLookRecordData];
}

#pragma mark - 获取客源带看记录数据
- (void)requestPassengerTakeLookRecordData {
    
    [kNetworkManager requestPassengerTakelookRecordWithAdbpId:self.passengerProgressModel.adbpId success:^(NSArray<SISSPassengerTakeLookModel *> *takeLookArr) {
        
        self.takeLookArr = takeLookArr;
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            [self.tableView reloadData];
            [self.tableView.mj_header endRefreshing];
        }];
        
        
    } failed:^(NSError *error) {
        [self.tableView.mj_header endRefreshing];
        NSLog(@"%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
